package org.edu.modules.research.rfunds.service.impl;

import org.edu.common.base.BasePageDto;
import org.edu.common.base.BaseServiceImpl;
import org.edu.common.utils.ConvertUtils;
import org.edu.common.base.BaseServiceImpl;
import org.edu.modules.research.rbase.service.VeJkyFileService;
import org.edu.modules.research.rfunds.mapper.VeJkyFundCheckIntroduceMapper;
import org.edu.modules.research.rfunds.entity.VeJkyFundCheckIntroduce;
import org.edu.modules.research.rfunds.dto.VeJkyFundCheckIntroduceDto;
import org.edu.modules.research.rfunds.service.VeJkyFundCheckIntroduceService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;


/**
 * 实现类
 */
@Service
public class VeJkyFundCheckIntroduceServiceImpl extends BaseServiceImpl<VeJkyFundCheckIntroduce, VeJkyFundCheckIntroduceMapper> implements VeJkyFundCheckIntroduceService {


    @Autowired
    private VeJkyFileService veJkyFileService;

    public IPage<VeJkyFundCheckIntroduceDto> pageDto(BasePageDto page, @Param(Constants.WRAPPER) Wrapper queryWrapper){
        return mapper.pageDto(page,queryWrapper);
    }
    /**
    * 查询实体类
    */
    public VeJkyFundCheckIntroduceDto findDtoById(String id) {
        VeJkyFundCheckIntroduce entity = super.findById(id);
        VeJkyFundCheckIntroduceDto dto = ConvertUtils.convertToDto(entity, VeJkyFundCheckIntroduceDto.class);
        return dto;
    }

    /**
    * 新增或者修改
    */
    @Transactional
    public void insertOrUpdate(VeJkyFundCheckIntroduceDto dto,Boolean isAdd){
        if(isAdd){
            dto.setCreateTime(new Date());
            super.insert(dto);
        }else{
            super.update(dto);
        }
        veJkyFileService.updateFiles(dto.getFileIds(),dto.getId()+"","project");
    }

}
